# -*- coding: utf-8 -*-
__author__ = 'xuliliang'
# @Time    : 2019/4/16 下午6:26
# @Author  : 'xuliliang'
# @Email   : xuliliang@u51.com
# @File    : test.py
# @Software: PyCharm


# import json
# import codecs
# import requests
# import  time

# print time.strptime()
# #
# # # 从本地上传数据文件
# # url_upload = 'http://xxx网址'
# #
# # # 报头为字典格式
# # head = {'Content-Type': 'application/json;charset=UTF-8'}
# #
# # with codecs.open("file.json", 'r', 'utf-8') as f:
# #     jdata = json.load(f)  # 打开文件，将字符串转换成数据类型
# #     print(jdata)
# #
# # res = requests.post(url_upload, data=json.dumps(jdata), headers=head)  # 把数据类型转换成字符串
# # print(res.text)
#
# data_set = [9, 1, 22, 31, 45, 3, 6, 2, 11]
#
# loop_count = 0
# for j in range(len(data_set)):
#     for i in range(len(data_set) - j - 1):  # -1 是因为每次比对的都 是i 与i +1,不减1的话,最后一次对比会超出list 获取范围,-j是因为,每一次大loop就代表排序好了一个最大值,放在了列表最后面,下次loop就不用再运算已经排序好了的值 了
#         if data_set[i] > data_set[i + 1]:  # switch
#             tmp = data_set[i]
#             data_set[i] = data_set[i + 1]
#             data_set[i + 1] = tmp
#         loop_count += 1
#     print(data_set)
# print(data_set)
# print("loop times", loop_count)
#
#
#
# smallest_num_index = 0  # 初始列表最小值,默认为第一个
#
# loop_count = 0
# for j in range(len(data_set)):
#     for i in range(j, len(data_set)):
#         if data_set[i] < data_set[smallest_num_index]:  # 当前值 比之前选出来的最小值 还要小,那就把它换成最小值
#             smallest_num_index = i
#         loop_count += 1
#     else:
#         print("smallest num is ", data_set[smallest_num_index])
#         tmp = data_set[smallest_num_index]
#         data_set[smallest_num_index] = data_set[j]
#         data_set[j] = tmp
#
#     print(data_set)
#     print("loop times", loop_count)
#
#
# source = [92, 77, 67, 8, 6, 84, 55, 85, 43, 67]
#
# for index in range(1, len(source)):
#     current_val = source[index]  # 先记下来每次大循环走到的第几个元素的值
#     position = index
#
#     while position > 0 and source[position - 1] > current_val:  # 当前元素的左边的紧靠的元素比它大,要把左边的元素一个一个的往右移一位,给当前这个值插入到左边挪一个位置出来
#         source[position] = source[position - 1]  # 把左边的一个元素往右移一位
#         position -= 1  # 只一次左移只能把当前元素一个位置 ,还得继续左移只到此元素放到排序好的列表的适当位置 为止
#
#     source[position] = current_val  # 已经找到了左边排序好的列表里不小于current_val的元素的位置,把current_val放在这里
#     print(source)

# str = 'arigin/develop'
# if str.startswith('origin'):
#     str = str.split('/')[1]
#     print "分割后分支:" + str
# else:
#     print  str
#
# import base64
#
# encodestr = base64.b64encode('ZGR90NGkdhNz'.encode('utf-8'))
# print(encodestr)
# print time.strftime("%Y%m%d") + "v2"
#
# path = "index.html-bak"
# bool = path.endswith("-bak")
# print(bool)


# -*- coding: utf-8 -*-
__author__ = 'xuliliang'
# @Time    : 2018/2/7 下午2:25
# @Author  : 'xuliliang'
# @Email   : xuliliang@u51.com
# @File    : vpn.py
# @Software: PyCharm

import pymysql

class MysqlApi(object):
  def __init__(self):
    self.host = '10.247.22.146'
    self.port = 3306
    self.user = 'geinihua'
    self.passwd = 'geinihua'
    self.dbname = 'demo';

    self.db  = pymysql.connect(host=self.host, port=self.port, user=self.user, passwd=self.passwd, db=self.dbname, charset='utf8')
    # 创建游标
    self.cursor = self.db.cursor(cursor=pymysql.cursors.DictCursor) #游标设置为字典类型
    # self.cursor = self.db.cursor() #默认是元组

  def user_insert(self):
    sql = "INSERT INTO `demo` (UserMongoId,name,age) VALUES ( 'abc284934', 'xull', '338')"
    try:

        for i in  range(10000):
          self.cursor.execute(sql)
      # db.commit()
      self.cursor.close()
      self.db.close()
    except pymysql.Warning as w:
        return w

myapi = MysqlApi()
myapi.user_insert()